#include "LevelLayer.h"
#include "Com/LevelItem.h"
#include "Persistence.h"
using namespace suta;
bool LevelLayer::init()
{
	bool ret=false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());
		{
			//bg
			CCSprite*bg=CCSprite::spriteWithFile("bg/bg_0.png");
			bg->setPosition(ccp(400,240));
			addChild(bg,-10);
		}
		
		int maxPassedLevel=Persistence::shardPersiatence()->getMaxPassedLevel();
		
		int last_enabled_index= ((maxPassedLevel==MAX_LEVEL)?MAX_LEVEL:maxPassedLevel+1);

		CCAssert(MAX_LEVEL+1==COLS*ROWS,"MAX_LEVEL+1!=COLS*ROWS");
		for (int i=0;i<(ROWS*COLS);i++)
		{
			int r=3-i/COLS;
			int c=1+i%COLS;
			LevelItem*item=LevelItem::node(i,i<=last_enabled_index);
			item->setPosition(ccp(800*c/(COLS+1),480*r/(ROWS+1)));
			addChild(item);
		}

		ret=true;
	} while (0);
	return ret;
}